﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using CPPEI.ETL.Domain;
using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi.IntegrityCheck
{
    [CPPEI.WebApi.AuthGetAction("IntegrityCheck", "GetList", "1.0")]
    public class GetListAction : BaseAction<GetListParams, GetListResult>
    {
        protected override ActionResult<GetListResult> OnExecute(ActionContext context,
            SysParameters sysParameters,
            GetListParams opParams)
        {
            List<CPPEI.ETL.Domain.IntegrityCheck.ICFactory.ICInfo> icInfoList = CPPEI.ETL.Domain.IntegrityCheck.ICFactory.EnumIC();

            GetListResult result = new GetListResult();
            for (int index = 0; index < icInfoList.Count; index++)
            {
                GetListResult.Item item = new GetListResult.Item();
                item.Id = icInfoList[index].Id;
                item.Name = icInfoList[index].Name;
                item.Description = icInfoList[index].Description;

                foreach (var p in icInfoList[index].ParameterList)
                {
                    item.ParameterList.Add(new GetListResult.Item.Parameter() { Name = p.Name, Caption = p.Caption, Type = p.Type.FullName });
                }
                result.Items.Add(item);
            }

            return new ActionResult<GetListResult>(result);
        }
    }

    public class GetListParams
    {
    }

    public class GetListResult
    {
        public List<Item> Items = new List<Item>();

        public class Item
        {
            public Guid Id { get; set; }
            public string Name { get; set; }
            public string Description { get; set; }

            public List<Parameter> ParameterList = new List<Parameter>();

            public class Parameter
            {
                /// <summary>
                /// 参数名
                /// </summary>
                public string Name { get; set; }
                /// <summary>
                /// 参数描述
                /// </summary>
                public string Caption { get; set; }
                /// <summary>
                /// 参数类型
                /// System.Int32
                /// System.String
                /// </summary>
                public string Type { get; set; }
            }
        }
    }
}
